package org.gvp.manager.repository.impl;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.gvp.manager.repository.SecurityPathRepository;
import org.gvp.manager.mapper.SecurityPathMapper;
import org.gvp.manager.pojo.SecurityPath;

import java.util.List;

/**
 * 请求路径信息表 数据层接口实现类
 */
@Repository
@RequiredArgsConstructor
public class SecurityPathRepositoryImpl implements SecurityPathRepository {
    private final SecurityPathMapper securityPathMapper;

    @Override
    public List<SecurityPath> searchNotLast() {
        return this.securityPathMapper.selectList(Wrappers.<SecurityPath>lambdaQuery()
                .eq(SecurityPath::getLast, false)
                .select(SecurityPath::getId,
                        SecurityPath::getParentId,
                        SecurityPath::getPattern,
                        SecurityPath::getExplain)
        );
    }

    @Override
    public int append(SecurityPath pojo) {
        return this.securityPathMapper.insert(pojo);
    }

    @Override
    public int modify(SecurityPath pojo) {
        return this.securityPathMapper.updateById(pojo);
    }

    @Override
    public int cancel(Integer id) {
        return this.securityPathMapper.deleteById(id);
    }

    @Override
    public SecurityPath searchById(Integer id) {
        return this.securityPathMapper.selectById(id);
    }

    @Override
    public List<SecurityPath> searchList() {
        return this.securityPathMapper.selectList(null);
    }

    @Override
    public Long searchCount(String field) {
        return this.securityPathMapper.selectCount(null);
    }

    @Override
    public List<SecurityPath> searchLimit(int start, int end) {
        return this.securityPathMapper.selectList(Wrappers.<SecurityPath>lambdaQuery()
                .last("LIMIT %d,%d".formatted(start, end))
                .orderByDesc(SecurityPath::getOrder)
                .orderByAsc(SecurityPath::getId)
        );
    }

}
